(function () {
    var self = null;
    window.SITE_CONFIG.mixinViewModule = {
        data: function () {
            return {
                // 设置属性
                mixinViewModuleOptions: {
                    activatedIsNeed: true, // 此页面是否在激活（进入）时，调用查询数据列表接口？
                    getDataListURL: "", // 数据列表接口，API地址
                    getDataListIsPage: false, // 数据列表接口，是否需要分页？
                    deleteURL: "", // 删除接口，API地址
                    deleteIsBatch: false, // 删除接口，是否需要批量？
                    deleteIsBatchKey: "id", // 删除接口，批量状态下由那个key进行标记操作？比如：pid，uid...
                    exportURL: "" // 导出接口，API地址
                },
                // 默认属性
                dataForm: {}, // 查询条件
                dataList: [], // 数据列表
                order: "", // 排序，asc／desc
                orderField: "", // 排序，字段
                page: 1, // 当前页码
                limit: 15, // 每页数
                total: 0, // 总条数
                dataListLoading: false, // 数据列表，loading状态
                dataListSelections: [], // 数据列表，多选项
                addOrUpdateVisible: false, // 新增／更新，弹窗visible状态
                addOrRechargeVisible: false,
                deatalViewVisible: false, // 详情窗口
                addViewVisible: false,

                orderChanne: [
                    {name: '微信', value: '0'},
                    {name: '支付宝', value: '1'},
                    {name: '网银充值', value: '3'},
                ],
                erCodeFlag: '',
                erCodeList: {
                    "0": [
                        {value: 'wechat_fkpay', name: '微信福卡e支付'},
                        {value: 'wechat_nxyspay', name: '微信农信易扫支付'},
                        {value: 'wechat_fixd', name: '微信固码'},
                        {value: 'wechat_xpos', name: '微信星pos'}
                    ],
                    "1": [
                        {value: 'zfb_fixed', name: '支付宝固码'},
                        {value: 'zfb_dynamic', name: '支付宝动态收款码'},
                        {value: 'poszfb_xpos', name: '支付宝星pos'}
                    ],
                    "3": [{
                        value: 'unionpay_dynamic', name: '动态收款码'
                    }]
                }
            };
        },
        filters: {
            // 支付状态el-tag类型转换
            payStatusFilter(status) {
                const statusMap = {
                    "-1": "info",
                    "0": "danger",
                    "1": "warning",
                    "2": "success"
                };
                return statusMap[status];
            },
            qrStatusFilter(status) {
                const statusMap = {
                    "0": "success",
                    "1": "danger"
                };
                return statusMap[status];
            },
            qrStatus(status) {
                const statusMap = {
                    "0": "成功",
                    "1": "失败"
                };
                return statusMap[status];
            },
            // 支付状态显示转换
            payStatus(status) {
                const statusMap = {
                    "-1": "无效",
                    "0": "支付中",
                    "1": "成功，未回调",
                    "2": "成功，已回调",
                    "3": "作废，解封金额"
                };
                return statusMap[status];
            },
            // 通道类型
            formatOrderChannel(status) {
                const statusMap = {
                    "0": "银行卡",
                    "1": "支付宝"
                };
                return statusMap[status];
            },
            // 通道归属
            formatConfigtype(status) {
                const statusMap = {
                    "0": "系统",
                    "1": "商户"
                };
                return statusMap[status];
            },
            formartErCode(status) {
                const statusMap = {
                    zfb_fixed: "支付宝固码",
                    zfb_dynamic: "支付宝动态收款码",
                    zfb_transfer: "支付宝转账",
                    zfb_new_transfer: "支付宝新转账",
                    zfb_tobank: "支付宝转银行卡",
                    alipay_mobileweb: "支付宝手机网站支付",
                    wechat_zfb: "合一码",
                    wechat_nxyspay: "微信农信易扫支付",
                    wechat_fixd: "微信固码",
                    unionpay_dynamic: "网银动态号"
                };
                return statusMap[status];
            },

            // 二维码el-tag类型转换
            erCodeFilter(status) {
                const statusMap = {

                    wechat_xpos: "success",
                    wechat_fkpay: "success",
                    wechat_nxyspay: "success",
                    wechat_fixd: "success",
                    zfb_fixed: "blue",
                    zfb_dynamic: "blue",
                    zfb_transfer: "blue",
                    zfb_new_transfer: "blue",
                    zfb_tobank: "blue",
                    alipay_mobileweb: "blue",
                    alipay_dmf: "blue",
                    zfb_nxyspay: "blue",
                    unionpay_dynamic: "danger"
                };
                return statusMap[status];
            },

            // 二维码el-tag类型转换
            // 通道类型el-tag类型转换
            orderChannelFilter(status) {
                const statusMap = {
                    "0": "success",
                    "1": "blue",
                    "2": "danger",
                    "3": "danger",
                    "4": "info"
                };
                return statusMap[status];
            },

            alipaytoaccountlogStatusFilter(status) {
                const statusMap = {
                    "0": "danger",
                    "-1": "danger",
                    "2": "success"
                };
                return statusMap[status];
            },
            alipaytoaccountlogStatus(status) {
                const statusMap = {
                    "0": "支付中",
                    "-1": "失败",
                    "2": "成功"
                };
                return statusMap[status];
            },
            alipaytoaccountlogTrstypeFilter(trstype) {
                const statusMap = {
                    "0": "danger",
                    "1": "success"

                };
                return statusMap[trstype];
            },
            alipaytoaccountlogTrstype(trstype) {
                const statusMap = {
                    "0": "转账",
                    "1": "红包"

                };
                return statusMap[trstype];
            },
            alipaytoaccountlogTypeFilter(trstype) {
                const statusMap = {
                    "0": "success",
                    "1": "danger"

                };
                return statusMap[trstype];
            },
            alipaytoaccountlogType(trstype) {
                const statusMap = {
                    "0": "公用账号",
                    "1": "商户账号"

                };
                return statusMap[trstype];
            },
            campStatusFilter(campstatus) {
                const statusMap = {
                    "CREATED": "warning",
                    "PAID": "已打款",
                    "READY": "danger ",
                    "CLOSED": "info ",
                    "SETTLE": "info ",
                    "PAUSE": "活动已暂停"

                };
                return statusMap[campstatus];
            },
            campStatus(campStatus) {
                const statusMap = {
                    "CREATED": "已创建未打款",
                    "PAID": "已打款",
                    "READY": "活动已开始 ",
                    "CLOSED": "活动已结束 ",
                    "SETTLE": "活动已清算 ",
                    "PAUSE": "活动已暂停"
                };
                return statusMap[campStatus];
            }
        },
        beforeCreate: function () {
            self = this;
        },
        created: function () {
            if (self.mixinViewModuleOptions.activatedIsNeed) {
                self.getDataList();
                // self.getSysInfo();
            }
        },
        methods: {
            codeView(value) {
                vm.erCodeFlag = value;
            },
            clearOrder(value) {
                vm.dataForm.trscode = '';
            },
            // 获取数据列表
            getDataList: function () {
                self.getSysInfo();
                self.dataListLoading = true;
                self.$http
                    .get(self.mixinViewModuleOptions.getDataListURL, {
                        params: _.merge(
                            {
                                order: self.order,
                                orderField: self.orderField,
                                page: self.mixinViewModuleOptions.getDataListIsPage
                                    ? self.page
                                    : null,
                                limit: self.mixinViewModuleOptions.getDataListIsPage
                                    ? self.limit
                                    : null
                            },
                            self.dataForm
                        )
                    })
                    .then(function (res) {
                        self.dataListLoading = false;
                        if (res.data.code !== 0) {
                            self.dataList = [];
                            self.total = 0;
                            return self.$message.error(res.data.msg);
                        }
                        self.dataList = self.mixinViewModuleOptions.getDataListIsPage
                            ? res.data.data.list
                            : res.data.data;
                        self.total = self.mixinViewModuleOptions.getDataListIsPage
                            ? res.data.data.total
                            : 0;
                    })
                    .catch(function () {
                        self.dataListLoading = false;
                    });
            },

            getSysInfo: function () {
                self.$http
                    .get(self.mixinViewModuleOptions.getOrderListURL, {
                        params: _.merge(
                            {
                                order: self.order,
                                orderField: self.orderField,
                                page: self.mixinViewModuleOptions.getDataListIsPage
                                    ? self.page
                                    : null,
                                limit: self.mixinViewModuleOptions.getDataListIsPage
                                    ? self.limit
                                    : null,
                                flag: 2
                            },
                            self.dataForm
                        )
                    })
                    .then(function (res) {
                        if (res.data.code !== 0) {
                            return self.$message.error(res.data.msg);
                        } else {
                            self.orderSub = res.data.data || self.orderSub;
                        }
                    })
                    .catch(function () {
                    });
            },
            // 多选
            dataListSelectionChangeHandle: function (val) {
                self.dataListSelections = val;
            },
            // 排序
            dataListSortChangeHandle: function (data) {
                if (!data.order || !data.prop) {
                    self.order = "";
                    self.orderField = "";
                    return false;
                }
                self.order = data.order.replace(/ending$/, "");
                self.orderField = data.prop.replace(/([A-Z])/g, "_$1").toLowerCase();
                self.getDataList();
            },
            // 分页, 每页条数
            pageSizeChangeHandle: function (val) {
                self.page = 1;
                self.limit = val;
                self.getDataList();
            },
            // 分页, 当前页
            pageCurrentChangeHandle: function (val) {
                self.page = val;
                self.getDataList();
            },
            // 新增 / 修改
            addOrUpdateHandle: function (id) {
                self.addOrUpdateVisible = true;
                self.$nextTick(function () {
                    self.$refs.addOrUpdate.dataForm.id = id;
                    self.$refs.addOrUpdate.init();
                });
            },
            addOrRechargeHandle: function (id) {
                self.addOrRechargeVisible = true;
                self.$nextTick(function () {
                    self.$refs.addOrRecharge.dataForm.id = id;
                    self.$refs.addOrRecharge.init();
                });
            },
            // 查看详情
            deatalVeiw: function (orderchannel) {
                self.deatalViewVisible = true;
                self.$nextTick(function () {
                    if (self.$refs.deatalView) {
                        self.$refs.deatalView.dataForm.orderchannel = orderchannel;
                        self.$refs.deatalView.init();
                    }
                });
            },
            // 删除
            deleteHandle: function (id) {
                if (
                    self.mixinViewModuleOptions.deleteIsBatch &&
                    !id &&
                    self.dataListSelections.length <= 0
                ) {
                    return self.$message({
                        message: self.$t("prompt.deleteBatch"),
                        type: "warning",
                        duration: 500
                    });
                }
                self
                    .$confirm(
                        self.$t("prompt.info", {handle: self.$t("delete")}),
                        self.$t("prompt.title"),
                        {
                            confirmButtonText: self.$t("confirm"),
                            cancelButtonText: self.$t("cancel"),
                            type: "warning"
                        }
                    )
                    .then(function () {
                        self.$http
                            .delete(
                                self.mixinViewModuleOptions.deleteURL +
                                (self.mixinViewModuleOptions.deleteIsBatch ? "" : "/" + id),
                                self.mixinViewModuleOptions.deleteIsBatch
                                    ? {
                                        data: id
                                            ? [id]
                                            : self.dataListSelections.map(function (item) {
                                                return item[
                                                    self.mixinViewModuleOptions.deleteIsBatchKey
                                                    ];
                                            })
                                    }
                                    : {}
                            )
                            .then(function (res) {
                                if (res.data.code !== 0) {
                                    return self.$message.error(res.data.msg);
                                }
                                self.$message({
                                    message: self.$t("prompt.success"),
                                    type: "success",
                                    duration: 500,
                                    onClose: function () {
                                        self.getDataList();
                                    }
                                });
                            })
                            .catch(function () {
                            });
                    })
                    .catch(function () {
                    });
            },
            zeroHandle: function (id) {
                if (
                    self.mixinViewModuleOptions.deleteIsBatch &&
                    !id &&
                    self.dataListSelections.length <= 0
                ) {
                    return self.$message({
                        message: self.$t("prompt.zeroBatch"),
                        type: "warning",
                        duration: 500
                    });
                }
                self
                    .$confirm(
                        self.$t("prompt.info", {handle: self.$t("delete")}),
                        self.$t("prompt.title"),
                        {
                            confirmButtonText: self.$t("confirm"),
                            cancelButtonText: self.$t("cancel"),
                            type: "warning"
                        }
                    )
                    .then(function () {

                        self.$http
                            .post(self.mixinViewModuleOptions.zeroURL, {
                                id: id
                            })
                            .then(function (res) {
                                if (res.data.code !== 0) {
                                    return self.$message.error(res.data.msg);
                                }
                                self.$message({
                                    message: self.$t("prompt.success"),
                                    type: "success",
                                    duration: 500,
                                    onClose: function () {
                                        self.getDataList();
                                    }
                                });
                            })
                            .catch(function () {
                            });
                    })
                    .catch(function () {
                    });
            },
            // 审核
            auditHandle: function (id) {
                if (!id) {
                    return self.$message({
                        message: "ID为空",
                        type: "warning",
                        duration: 500
                    });
                }
                self
                    .$confirm(
                        self.$t("prompt.info", {handle: self.$t("audit")}),
                        self.$t("prompt.title"),
                        {
                            confirmButtonText: "通过",
                            cancelButtonText: "不通过",
                            distinguishCancelAndClose: true,
                            type: "warning"
                        }
                    )
                    .then(function () {
                        self.$http
                            .post(self.mixinViewModuleOptions.auditURL, {
                                id: id,
                                status: 1
                            })
                            .then(function (res) {
                                if (res.data.code !== 0) {
                                    return self.$message.error(res.data.msg);
                                }
                                self.$message({
                                    message: self.$t("prompt.success"),
                                    type: "success",
                                    duration: 500,
                                    onClose: function () {
                                        self.getDataList();
                                    }
                                });
                            })
                            .catch(function () {
                            });
                    })
                    .catch(function (action) {
                        if (action == "cancel") {
                            self.$http
                                .post(self.mixinViewModuleOptions.auditURL, {
                                    id: id,
                                    status: -1
                                })
                                .then(function (res) {
                                    if (res.data.code !== 0) {
                                        return self.$message.error(res.data.msg);
                                    }
                                    self.$message({
                                        message: self.$t("prompt.success"),
                                        type: "success",
                                        duration: 500,
                                        onClose: function () {
                                            self.getDataList();
                                        }
                                    });
                                })
                                .catch(function () {
                                });
                        }
                    });
            },

            // 查看详情
            addViewHandle: function (val) {
                self.addViewVisible = true;
                self.$nextTick(function () {
                    self.$refs.addView.dataForm = val;
                    self.$refs.addView.visible = true;
                });
            },
            // 导出
            exportHandle: function () {
                window.location.href =
                    window.SITE_CONFIG["apiURL"] +
                    self.mixinViewModuleOptions.exportURL +
                    "?" +
                    Qs.stringify(self.dataForm);
            }
        }
    };
})();
